import React, {Component} from 'react';
import PropTypes from 'prop-types';
import TodoButton from '../TodoButton/index.jsx';

class TodoListAdd extends Component {

  constructor(props) {
    super(props);
    this._add = this._add.bind(this);
  }

  static propTypes = {
    _onAddClick: PropTypes.func.isRequired
  }

  static defaultProps = {

  }


  _add() {
    let input = this.myinput;

    if (input.value != '') {

      this.props._onAddClick(input.value);
      input.value = '';
    } else {
      alert('请输入内容');
    }
  }

  render() {

    return (
      <div style = {{display: 'flex'}}>
        <input
          ref={(input) => {this.myinput=input;}}/>
        <TodoButton
          _onClick={this._add}
          name = 'add'
        />
      </div>
    );
  }
}


export default TodoListAdd;

